package com.baoer.service.impl;

import com.baoer.R;
import com.baoer.dao.ProductDao;
import com.baoer.entity.Product;
import com.baoer.entity.ProductState;
import com.baoer.service.ProductService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service 
@RequiredArgsConstructor
public class ProductServiceImpl implements ProductService {
//    @Autowired
    private final ProductDao productDao;
    


    @Override
    public R getAllProducts(Map<String, Object> map) {
        List<Product> products = productDao.selectAllProducts();
        return R.ok(products);
    
    }

    @Override
    public R getOutboundProducts(Map<String, Object> map) {
        List<Product> products = productDao.selectOutboundProducts();
        return R.ok( products);
    }

    @Override
    public  R getAroundProducts(Map< String, Object>  map) {
        List<Product> products = productDao.selectAroundProducts();
        return  R.ok( products);
    }

    @Override
    public R getOtherProducts( Map<String, Object> map) {
        List<Product> products = productDao.selectOtherProducts();
        return  R.ok( products);
    }

    @Override
    public List<Product> searchProducts(Map<String, Object> params) {
        return productDao.searchProducts(params);
    }

    @Override
    public int updateProduct(Product product) {
        return productDao.updateProduct(product);
    }
    @Override
    public int deleteProduct(Integer productId) {
        return productDao.deleteProduct(productId);
    }

    @Override
    public Product getProductWithStoreAndManager(Integer productId) {
        return productDao.getProductWithStoreAndManager(productId);
    }


    @Override
    public int setProductState(ProductState productState) {
        ProductState existingState = productDao.getProductStateByProductId(productState.getProductId());
        if (existingState != null) {
            // 有记录，调用修改接口
            return productDao.updateProductState(productState);
        } else {
            // 无记录，调用添加接口
            return productDao.addProductState(productState);
        }
    }

    @Override
    public R getNewestProducts( Map<String, Object> map) {
        List<Product> products = productDao.selectNewestProducts();
        return R.ok(products);
    }

    @Override
    public R getSpecialOfferProducts(Map <String, Object> map) {
        List<Product> products = productDao.selectSpecialOfferProducts();
        return  R.ok( products);
    }

    @Override
    public R getHotSellingProducts(Map <String, Object> map) {
        List<Product> products = productDao.selectHotSellingProducts();
        return  R.ok( products);
    }
}
